<template>
    <div class="layout">
        <div class="pre">
            <el-radio-group v-model="currentIndex">
                <el-radio-button :label="1">超过1天未跟进</el-radio-button>
                <el-radio-button :label="2">超过2天未跟进</el-radio-button>
                <el-radio-button :label="3">超过3天未跟进</el-radio-button>
                <el-radio-button :label="4">超过4天未跟进</el-radio-button>
            </el-radio-group>
            <div v-show="!isNoMessage1" id="echarts" ref="myRef_one" class="min"></div>
            <div v-show="isNoMessage1" class="no_data">
                <img class="no_img" src="@/assets/noData.png" alt="" />
                <div class="emty_title">暂无数据</div>
            </div>
        </div>
        <div class="pre" style="padding-top: 90px">
            <!-- <div class="pre_title">
        <span class="title-text">详细数据</span>
        <span class="export" @click="exportCus()">导出</span>
      </div> -->
            <div v-show="!isNoMessage2" id="echartstwo" ref="myRef_two" class="min"></div>
            <div v-show="isNoMessage2" class="no_data">
                <img class="no_img" src="@/assets/noData.png" alt="" />
                <div class="emty_title">暂无数据</div>
            </div>
        </div>
    </div>
</template>
<script lang="ts" setup>
import { onMounted, reactive, ref, inject, watch } from 'vue';
import { getBoardtopexport } from '@/api/customerbulletin/bulleinManage';
import { getDay } from '@/utils/timeCycle';
const echarts = inject('ec');
const currentIndex = ref(1);
const emit = defineEmits(['targetData']);
const myRef_one = ref(null);
const myRef_two = ref(null);
const isNoMessage1 = ref(false);
const isNoMessage2 = ref(false);
const props = defineProps(['completionDatathree', 'deliveryDatathree', 'paramsthree', 'timedata']);
const tableData = ref(null);
const params = reactive({
    start_time: getDay(-7),
    end_time: getDay(0),
    employee_ids: '',
    type: currentIndex.value
});
const timedatalist = ref();
const getChart = (data: any) => {
    const datatime = data.time;
    const dataname = data.no_follow_name;
    const datalist = data.no_follow;
    datalist.map((item: any) => {
        (item.smooth = true), (item.symbol = 'circle');
    });
    if (data.length == 0) {
        isNoMessage1.value = true;
        return;
    } else {
        isNoMessage1.value = false;
    }
    const myChart_one = echarts.init(myRef_one.value);
    myChart_one.setOption({
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            bottom: 15,
            left: 'center',
            data: dataname
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '8%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {
                    title: '下载图片',
                    name:
                        '客户阶段走势' +
                        ['超过1天未跟进', '超过2天未跟进', '超过3天未跟进', '超过4天未跟进'][currentIndex.value - 1] +
                        params.end_time
                }
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: datatime
        },
        yAxis: {
            type: 'value',
            name: '未跟进情况',
            position: 'left',
            alignTicks: true
        },
        series: datalist
    });
};
const getChartTwo = (data: any) => {
    const datatime = data.time;
    const dataname = data.following_name;
    const datalist = data.following;
    datalist.map((item: any) => {
        (item.smooth = true), (item.symbol = 'circle');
    });
    if (data.length == 0) {
        isNoMessage2.value = true;
        return;
    } else {
        isNoMessage2.value = false;
    }
    const myChart_two = echarts.init(myRef_two.value);
    myChart_two.setOption({
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            bottom: 15,
            left: 'center',
            data: dataname
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '8%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: datatime
        },
        yAxis: {
            type: 'value',
            name: '已跟进情况',
            position: 'left',
            alignTicks: true
        },
        series: datalist
    });
};

const datatable = (data: any) => {
    tableData.value = data;
};
// 导出客户
const exportCus = () => {
    params.start_time = props.paramsthree.start_time;
    params.end_time = props.paramsthree.end_time;
    params.employee_ids = props.paramsthree.employee_ids;
    getBoardtopexport(params).then((res: any) => {
        window.location = res.url;
    });
};
watch(
    () => props.completionDatathree,
    val => {
        getChart(val);
    }
);
watch(
    () => props.deliveryDatathree,
    val => {
        getChartTwo(val);
    }
);
watch(
    () => props.timedata,
    val => {
        timedatalist.value = val.end_time;
    }
);
watch(currentIndex, val => {
    currentIndex.value = val;
    params.type = val;
    emit('targetData', val);
});
// defineExpose({ change }) //像父组件抛出方法
</script>
<style lang="scss" scoped>
.layout {
    width: 100%;
    margin-top: 16px;

    .pre {
        width: 100%;
        height: 750px;
        box-sizing: border-box;
        background: #fff;

        .pre_title {
            display: flex;
            align-items: center;
            justify-content: space-between;

            .btn_left {
                display: flex;
                align-items: center;

                .btn_item {
                    padding: 10px 18px;
                    background: #fff;
                    font-size: 16px;
                    line-height: 16px;
                    font-weight: 500;
                    color: #ff6b00;
                    border: 1px solid #ff6b00;
                    cursor: pointer;
                    flex-shrink: 0;
                }

                .active {
                    background: #ff6b00;
                    color: #fff;
                }
            }
        }

        .el-radio-group {
            margin: 0 20px;
        }

        &_title {
            padding: 20px 24px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;

            .export {
                display: inline-block;
                width: 64px;
                height: 36px;
                text-align: center;
                line-height: 36px;
                background: #fff;
                border-radius: 4px;
                border: 1px solid #eaeaea;
                cursor: pointer;
            }
        }

        .title-text {
            line-height: 38px;
        }

        .min {
            height: 100%;
            background: #fff;
        }
    }

    .no_data {
        height: 500px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;

        .no_img {
            margin-left: 35px;
        }
    }
}

.el-form-item {
    margin-bottom: 0;
}
</style>
